package com.neusoft.service.impl;

import com.neusoft.mapper.CheckRequestMapper;
import com.neusoft.mapper.InspectionRequestMapper;
import com.neusoft.mapper.MedicalTechnologyMapper;
import com.neusoft.service.InspectionRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class InspectionRequestServiceImpl implements InspectionRequestService {

    @Autowired
    InspectionRequestMapper inspectionRequestMapper;

    @Autowired
    MedicalTechnologyMapper medicalTechnologyMapper;
    @Override
    public String saveInspectionRequest(Map<String, Object> inspectionRequest) {
        List<Map<String,Object>> checkMedicalTechnologyList=(List<Map<String, Object>>) inspectionRequest.get("checkMedicalTechnologyList");

        if (checkMedicalTechnologyList.size()>0){
            for (int i=0;i<checkMedicalTechnologyList.size();i++){
                Map<String,Object> element=checkMedicalTechnologyList.get(i);
                inspectionRequest.put("medical_technology_id",element.get("id"));
                inspectionRequest.put("inspection_state","已缴费");
                // checkRequest.put("checkMedicalTechnologyList",element);
                inspectionRequestMapper.insert(inspectionRequest);
            }
        }

        return "成功";
    }
    @Override
    public Integer getFinishInspection() {
        return inspectionRequestMapper.selectFinshInspection();
    }

    @Override
    public List<Integer> getWaitRegisterIdList() {
        return inspectionRequestMapper.selectWaitInspection();
    }

    @Override
    public void updateInspectionRequestTable(Integer inspectionId, Integer employeeId) {
        LocalDateTime inspectionTime=LocalDateTime.now();
        inspectionRequestMapper.updateInspectionRequestTable(inspectionId,employeeId,inspectionTime);
    }

    @Override
    public List<Map<String, Object>> searchInspectionItems(Integer registerId) {
        return inspectionRequestMapper.selectItem(registerId);
    }
}
